// pages/reply/index.js
const API = require('../../common/constant');
const util = require('../../utils/util');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    noSatis: true,    
    tagsExample: [
      {
        text: "",
        top: "10",
        left: "85"
      },
      {
        text: "",
        top: "0",
        left: "472"
      },
      {
        text: "",
        top: "86",
        left: "289"
      },
      {
        text: "",
        top: "130",
        left: "550"
      },
      {
        text: "",
        top: "200",
        left: "94"
      },
      {
        text: "",
        top: "242",
        left: "458"
      },
      {
        text: "",
        top: "324",
        left: "198"
      }
    ]
  },
  chooseIcon(e){
    console.log(e);
    this.setData({
      noSatis: e.currentTarget.dataset.icon=="true" ? true : false
    })
  },
  getInput(e){
    this.setData({
      iptVal: e.detail.value
    })
  },
  getEventContent(e) {
    this.setData({
      content: e.detail.value
    })
  },
  saveUserReply() {
    if(this.data.repling){
      return
    }
    this.setData({
      repling: true
    })
    wx.showLoading({})
    util.httpbody({
      url: API.URL.REPLY.SAVE_USER_REPLY,
      data: {
        "content": this.data.content,
        "idEventInfoId": this.data.eventId,
        "isSatisfaction": this.data.noSatis,
        "sign": this.data.iptVal,
        "toUserId": this.data.userId
      },
      success: res => {
        this.setData({
          repling: false,
          iptVal: '',
          content: ''
        })
        wx.hideLoading()
        app.showUserInfo('评论成功', 'none', 1500)
        console.log('res', res)
      },
      fail: err => {
        console.log('err', err)
        wx.hideLoading()
        app.showUserInfo('评论失败', 'none', 1500)
        this.setData({
          repling: false,
          iptVal: '',
          content: ''
        })
      }
    })
  },
  getUserTags(param) {
    util.httpbody({
      url: API.URL.REPLY.FIND_REPLY_INFO,
      data: {
        id: param,
        pageIndex: 1,
        pageSize: 7
      },
      success: res => {
        console.log('res', res)
        let bussData = res.data.bussData
        let tagsExample = this.data.tagsExample
        bussData.forEach((item, index) => {
          tagsExample[index].text = item.sign
        })
        this.setData({
          tagsExample: tagsExample
        })
      },
      fail: err => {
        console.log('err', err)
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // let id = options.id
    this.setData({
      eventId: options.eventId,
      userId: options.userId
    })
    this.getUserTags(options.userId)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})